<!--_meta 作为公共模版分离出去-->
{include file="public/meta" /}
<!--/meta 作为公共模版分离出去-->

<title>新增文章 - 资讯管理 - h-ui.admin.pro v1.0</title>
<meta name="keywords" content="h-ui.admin.pro v1.0,H-ui网站后台模版,后台模版下载,后台管理系统模版,HTML后台模版下载">
<meta name="description" content="h-ui.admin.pro v1.0，是一款由国人开发的轻量级扁平化网站后台模板，完全免费开源的网站后台管理系统模版，适合中小型CMS后台系统。">
</head>
<body>
<div class="wap-container">
    <nav class="breadcrumb" style="background-color:#fff;padding: 0 24px">
        首页
        <span class="c-gray en">/</span>
        资讯管理
        <span class="c-gray en">/</span>
        新增资讯
        <a class="btn btn-success radius f-r" style="line-height:1.6em;margin-top:3px"
           href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
    </nav>
    <article class="Hui-admin-content clearfix">
        <div class="panel">
            <div class="panel-body">
                <form class="form form-horizontal" id="form-article-add">
                    <input type="hidden" value="{$model['id']}" name="id">
                    <div class="row clearfix">
                        <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>文章标题：</label>
                        <div class="form-controls col-xs-8 col-sm-9">
                            <input type="text" class="input-text" value="{$model.title}" placeholder="" id="articleTitle"
                                   name="title">
                        </div>
                    </div>
                    <div class="row clearfix">
                        <label class="form-label col-xs-4 col-sm-2">文章内容：</label>
                        <div class="form-controls col-xs-8 col-sm-9">
                            <script id="articleEditor" type="text/plain" style="width:100%;height:400px;">{$model.content|raw}</script>
                        </div>
                    </div>
                    <div class="row clearfix">
                        <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                            <button class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i>
                                保存并提交
                            </button>
                            <button onClick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </article>
</div>
<!--_footer 作为公共模版分离出去-->
{include file="public/footer" /}
<!--/_footer /作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="{__STATIC_PATH}admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="{__STATIC_PATH}admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="{__STATIC_PATH}admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="{__STATIC_PATH}admin/lib/webuploader/0.1.5/webuploader.min.js"></script>
<script type="text/javascript" src="{__STATIC_PATH}admin/lib/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="{__STATIC_PATH}admin/lib/ueditor/1.4.3/ueditor.all.min.js"></script>
<script type="text/javascript" src="{__STATIC_PATH}admin/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="{__STATIC_PATH}admin/static/business/js/main.js"></script>
<script type="text/javascript">
	function upimg(obj) {
		if (obj.value == "") {
			return;
		}
		var formdata = new FormData();
		//<input type="file" name="img" value="" />
		formdata.append("img", $(obj)[0].files[0]);//获取文件法二
		$.ajax({
			type: 'post',
			url: "image", //接口
			data: formdata,
			cache: false,
			processData: false, // 不处理发送的数据，因为data值是Formdata对象，不需要对数据做处理
			contentType: false, // 不设置Content-type请求头
			success: function (response) {
				// console.log(response);
				var html = '<div style="position: relative;margin-right: 20px;margin-bottom: 15px;width: 132px;display: inline-block;border: 1px solid #CCC;background:#EEE;">'
						+ '<span style="display: block;width: 120px;height: 80px;border: 1px solid #F2F1F0;margin: 5px;overflow: hidden;">'
						+ '<img src="' + response + '" style="width: 100%;" />'
						+ '</span>'
						+ '<input type="hidden" name="img" value="' + response + '" />'
						+ '<a onclick="delImg(this);" style="z-index: 10;display: block;top: -8px;cursor:pointer;right: -8px;position:absolute;width: 20px;height: 20px;background: #CCC;border-radius:100%;text-align:center;line-height: 20px;border: 1px solid #C1C1C1;color: #555;">X</a>'
						+ '</div>';

				$('#img-list-box').html(html);
			},
			error: function () {
			}
		});
	}

	function delImg(obj) {
		$(obj).parent('div').remove();
	}
    function layer_close() {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }
    $(function () {
        // 文章摘要
        $(".textarea-article").Huitextarealength({
            minlength: 10,
            maxlength: 500
        });

        // 文章内容 实例化百度富文本编辑器
        var ue = UE.getEditor('articleEditor');
        // 表单提交验证
        $("#form-article-add").validate({
            onkeyup: false,
            focusCleanup: false,
            success: "valid",
            submitHandler: function (form) {
                $.ajax({
                    url: "add",
                    type: "post",
                    data: $("form").serialize(),
                    success: function (res) {
                        if (res.code == 1) {
                            layer.msg(res.msg, {
                                icon: 1,
                                time: 1000 //2秒关闭（如果不配置，默认是3秒）
                            }, function () {
                                //do something
                                parent.location.replace(parent.location.href)
                                parent.layer.close(index);
                            });
                        } else {
                            layer.msg(res.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            }
        });
    });
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>
